package action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import vue.AdminCombinationForm;
import bean.CombinaisonBean;

public class ActionValidateCombination extends AbstractAction {
	
	AdminCombinationForm _adminCombinationForm;
	
	public ActionValidateCombination(AdminCombinationForm adminCombinationForm)
	{
		super();
		_adminCombinationForm = adminCombinationForm;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
		CombinaisonBean combinationValidated = _adminCombinationForm.getSelectedCombination();
		combinationValidated.setName(_adminCombinationForm.getName());
		combinationValidated.setP1(_adminCombinationForm.getColor1());
		combinationValidated.setP2(_adminCombinationForm.getColor2());
		combinationValidated.setP3(_adminCombinationForm.getColor3());
		combinationValidated.setP4(_adminCombinationForm.getColor4());
		
	
		ActionCreateCombinaison action = new ActionCreateCombinaison();
		CombinaisonBean c = action.doCreateCombinaison(combinationValidated);
			
		if(c != null)
		{
			_adminCombinationForm.setIsCreatedNoValidated(false);
		}
		else
		{
			JOptionPane.showMessageDialog(_adminCombinationForm, _adminCombinationForm.getBundle().getString("messageErrorCreationCombination") , _adminCombinationForm.getBundle().getString("titleErrorCreationCombination"), JOptionPane.ERROR_MESSAGE);
		}	
		
	}

}
